package com.pro.controller;

import com.pro.pojo.JsProduct;
import com.pro.pojo.JsonData;
import com.pro.service.JsProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/goodsTable")
public class JsProductController {
    @Autowired
    private JsProductService service;
    @RequestMapping("/getTable")
    public JsonData getTable(JsProduct jsProduct){
        return service.getTable(jsProduct);
    }
    @RequestMapping("/getProduct")
    public JsonData getProduct(Integer productId,Integer updateId){
         return service.getProduct(productId,updateId);
    }
    @RequestMapping("/addProduct")
    public JsonData addProduct(JsProduct jsProduct){
        jsProduct.setCreateDate(new Date());
        Boolean aBoolean = service.addProduct(jsProduct);
        return jsProduct!=null?JsonData.buildSuccess(jsProduct):JsonData.buildError("服务端错误");
    }
    @RequestMapping("/updateProduct")
    public JsonData updateProduct(JsProduct jsProduct,Integer updateId){
         return service.updateProduct(jsProduct,updateId);
    }
    @RequestMapping("/delProduct")
    public JsonData delProduct(Integer productId,Integer updateId){
         return service.delProduct(productId,updateId);
    }
    @RequestMapping("/updateProductStatus")
    public JsonData updateProductStatus(String productSate, Integer productId){
        Boolean aBoolean=service.updateProductstatus(productSate,productId);
        return aBoolean!=false?JsonData.buildSuccess(aBoolean):JsonData.buildError("服务端错误");
    }
    @RequestMapping("/getSearchProduct")
    public JsonData getSearchProduct(JsProduct jsProduct){
        return service.getSearchProduct(jsProduct);
    }

    @RequestMapping("/productSate")
    public JsonData productSate(){
        int productSate = service.productSate();
        return productSate>=0?JsonData.buildSuccess(productSate):JsonData.buildError("服务端错误");
    }
}
